#include <stdio.h>

#define GENERIC_PARITY(type) \
type type##_parity(type x) { \
	unsigned type u = x; \
	unsigned type bits = sizeof(type) * 8; \
	while (bits != 1) { \
		bits /= 2; \
		u ^= (u >> bits); \
	} \
	return u & 1; \
}

GENERIC_PARITY(char)
GENERIC_PARITY(short)
GENERIC_PARITY(int)
GENERIC_PARITY(long)


int main(int argc, char* argv[]) {
	int a = 0xff00ff00;
	int b = 0xff00fe00;
	printf("%d, %d\n", int_parity(a), int_parity(b));
	return 0;
}
